﻿using EA.BA;
using EA.Common;
using EA.DTO;
using EAWebAdmin.template;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EAAdmin
{
    public partial class ViewMember : WebPage
    {
        override
        protected void Load(object sender, EventArgs e)
        {
            MemberBA memberBA = new MemberBA();
            List<MemberTO> listMember = memberBA.GetAllMember();
            Attributes.Add("listMember", listMember);
        }

        public void Delete(HttpRequest Request, HttpResponse Response)
        {
            if (Request["id"] != null && !"".Equals(Request["id"]) && StringUtil.IsPositiveNumber(Request["id"]))
            {
                MemberBA memberBA = new MemberBA();
                int ID = Convert.ToInt32(Request["id"]);
                MemberTO memberTO = memberBA.GetMemberByID(ID);
                if (memberTO == null)
                {
                    Attributes.Add("err", "Member is invalid");
                    this.isLoad = true;
                    return;
                }
                Boolean stt = memberBA.DeleteMember(ID);
                if (stt)
                {
                    Attributes.Add("success", "Delete successfully");          
                    this.isLoad = true;
                }
                else
                {
                    Attributes.Add("err", "Delete faulty");
                    this.isLoad = true;
                    return;
                }
            }
        }
    }
}